package com.investment.advisor.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Set;

@Entity
@Table(name = "funds")
@Getter
@Setter
@NoArgsConstructor
@ToString(exclude = {"tags"})
public class Fund {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(unique = true, nullable = false, length = 10)
    private String code;

    @Column(nullable = false, length = 100)
    private String name;

    @Column(length = 50)
    private String type;

    @Column(precision = 10, scale = 4)
    private BigDecimal nav;  // 最新净值

    @Column(precision = 10, scale = 4)
    private BigDecimal dailyReturn;  // 日涨跌幅

    @Column(precision = 10, scale = 4)
    private BigDecimal weeklyReturn;  // 周涨跌幅

    @Column(precision = 10, scale = 4)
    private BigDecimal monthlyReturn;  // 月涨跌幅

    @Column(precision = 10, scale = 4)
    private BigDecimal yearlyReturn;  // 年涨跌幅

    @Column(precision = 10, scale = 4)
    private BigDecimal size;  // 基金规模（亿元）

    @Column(length = 100)
    private String manager;  // 基金经理

    @Column(length = 100)
    private String company;  // 基金公司

    @Column(length = 1000)
    private String description;  // 基金描述

    @Column
    private Integer rating;  // 基金评级（1-5星）

    @JsonManagedReference
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
        name = "fund_tag",
        joinColumns = @JoinColumn(name = "fund_id"),
        inverseJoinColumns = @JoinColumn(name = "tag_id")
    )
    private Set<Tag> tags;  // 基金标签

    @CreationTimestamp
    private LocalDateTime createTime;

    @UpdateTimestamp
    private LocalDateTime updateTime;
} 